using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Rotempco.Core.Logic
{
    public class HashLogic
    {
        public static string GetHash(byte[] byteArray)
        {
            byte[] keyArray;

            MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
            keyArray = hashmd5.ComputeHash(byteArray);
            hashmd5.Clear();

            return Convert.ToBase64String(keyArray, 0, keyArray.Length);
        }

        public static string GetHash(string input)
        {
            byte[] inputBytes = UTF8Encoding.UTF8.GetBytes(input);
            return GetHash(inputBytes);
        }

        public static string GetSHA256(string input)
        {
            byte[] inputBytes = UTF8Encoding.UTF8.GetBytes(input);
            return GetSHA256(inputBytes);
        }

        public static string GetSHA256(byte[] input)
        {
            byte[] hashValue;

            SHA256Managed hashString = new SHA256Managed();
            string hex = "";

            hashValue = hashString.ComputeHash(input);
            foreach (byte x in hashValue)
            {
                hex += String.Format("{0:x2}", x);
            }
            return hex;
        }

        public static string GetSHA512(string input)
        {
            byte[] inputBytes = UTF8Encoding.UTF8.GetBytes(input);
            return GetSHA512(inputBytes);
        }

        public static string GetSHA512(byte[] input)
        {
            byte[] hashValue;

            SHA512Managed hashString = new SHA512Managed();
            string hex = "";

            hashValue = hashString.ComputeHash(input);
            foreach (byte x in hashValue)
            {
                hex += String.Format("{0:x2}", x);
            }
            return hex;
        }


    }
}
